
var vue;
$(function(){
    vue = new Vue({
        el: '#page',
        data: {
            memberPhone:"",
            memberHeadMsg:"",
            memberInfo:{
                phone:"",
                name:""
            },
            loginHistory:[],
            pageShow:'member',
            feedback:{
                "content":"",
                "file":"false",
                "mail":""
            },
            phoneZone:{},
            phoneZoneCurr:'+86',
            Authentication:{
                "authentication":0,//0未认证，1审核中, 2已认证
                "name":"张一丰",
                "cardNo":"510256198211085666",
                "imgFace":"image/img227_1.png",
                "imgBack":"image/img227_2.png",
                "imgFaceOk":false,
                "imgBackOk":false
            }
        },
        methods:{
            //获取数据
            getData:function (data) {
                vue.memberInfo = {
                    phone : data.phone,
                    name : data.name
                }
            },
            //退出登录
            loginOut:function () {
                var data = '{"Action":"002021",'+wsStr+'"u_id":0,"u_loginname":null,"u_pswd":null,"Tag":{"c_loginname":"'+u_name+'","c_password":"'+u_password+'"},"SerializString":null}';
                wsFun(base64_encode(zip(data)));
                localStorage.isLogin = false;
                isLoginFun()
            },
            //--修改登录密码
            loginPasswordSubmit:function () {
                var password = $.trim(this.$refs.loginPassword.value),
                    passwordNew = $.trim(this.$refs.loginPasswordNew.value),
                    passwordNew2 = $.trim(this.$refs.loginPasswordNew2.value),
                    lzm = $.trim(this.$refs.loginLzm.value);
                if(password.length < 6 || passwordNew.length < 6){
                    pageTips2("密码输入错误");
                    return
                }
                if(passwordNew !== passwordNew2){
                    pageTips2("两次密码输入不一致");
                    return
                }
                var data = '{"action":"002024",'+wsStr+'"Tag":{"c_mobile":"'+this.memberInfo.phone+'","c_password":"'+password+'","c_newpassword":"'+passwordNew+'","c_smscode":"'+lzm+'"},"SerializString":null}';
                wsFun(base64_encode(zip(data)))
            },
            //--修改手机号
            phoneUpdateSubmit:function () {
                var phone = $.trim(this.$refs.phonePhone.value),
                    lzm = $.trim(this.$refs.phoneLzm.value);
                if(isPhone(phone) === false){
                    pageTips2("手机号码不正确");
                    return;
                }
                var data = '{"action":"002025",'+wsStr+'"Tag":{"c_mobile":"'+this.memberInfo.phone+'","c_newmobile":"'+phone+'","c_smscode":"'+lzm+'"},"SerializString":null}';
                wsFun(base64_encode(zip(data)))
            },
            //--修改资金密码
            capitalUpdate:function(){
                var password = $.trim(this.$refs.capitalUpdatePassword.value),
                    passwordNew = $.trim(this.$refs.capitalUpdatePasswordNew.value),
                    lzm = $.trim(this.$refs.capitalUpdateLzm.value);
                if(password.length < 6 || passwordNew.length < 6){
                    pageTips2("密码长度最少6位");
                    return
                }
                var data = '{"action":"002026",'+wsStr+'"Tag":{"c_mobile":"'+this.memberInfo.phone+'","c_tradepassword":"'+password+'","c_newtradepassword":"'+passwordNew+'","c_smscode":"'+lzm+'"}}';
                wsFun(base64_encode(zip(data)))
            },
            //--忘记资金密码
            capitalForget:function(){
                var password = $.trim(this.$refs.capitalForgetPassword.value),
                    passwordConfirm = $.trim(this.$refs.capitalForgetPasswordConfirm.value),
                    lzm = $.trim(this.$refs.capitalForgetLzm.value);
                if(password.length < 6){
                    pageTips2("密码长度最少6位");
                    return
                }
                if(password !== passwordConfirm){
                    pageTips2("两次密码输入不一致");
                    return
                }
                var data = '{"action":"002027",'+wsStr+'"Tag":{"c_mobile":"'+this.memberInfo.phone+'","c_tradepassword":"'+password+'","c_smscode":"'+lzm+'"}}';
                wsFun(base64_encode(zip(data)))
            },
            //--获取身份认证数据
            getAuthenticationData:function (data) {
                if(data.authentication === 0){
                    vue.Authentication.authentication = data.authentication
                }else{
                    vue.Authentication = {
                        "authentication": data.authentication,
                        "name": data.name,
                        "cardNo": data.cardNo,
                        "imgFace": data.imgFace,
                        "imgBack": data.imgBack
                    }
                }
            },
            //--身份认证提交
            authenticationSubmit:function () {
                var name = $.trim(this.$refs.authenticationName.value),
                    cardNo = $.trim(this.$refs.authenticationCardNo.value),
                    imgFace = this.Authentication.imgFace,
                    imgBack = this.Authentication.imgBack;
                if(isRealName(name) === false){
                    pageTips2('请填写真实姓名')
                }else if(IdentityCodeValid(cardNo) === false){
                    pageTips2('身份证号码错误')
                }else if(this.Authentication.imgFaceOk === false){
                    pageTips2('请上传身份证正面')
                }else if(this.Authentication.imgBackOk === false) {
                    pageTips2('请上传身份证背面')
                }else{
                    var data = '{"action":"002028",'+wsStr+'"u_id":0,"u_loginname":null,"u_pswd":null,"Tag":{"c_mobile":"'+ this.memberInfo.phone +'","c_cnname":"'+ name +'","c_idcard":"'+ cardNo +'","c_idcard1":"'+ imgFace +'","c_idcard2":"'+ imgBack +'"},"SerializString":null}';
                    wsFun(base64_encode(zip(data)));
                    this.Authentication.name = name;
                    this.Authentication.cardNo = cardNo;
                    this.memberInfo.name = name;
                }
            },
            //--问题反馈提交
            feedbackSubmit:function(){
                var content = this.feedback.content,
                    file = this.feedback.file,
                    mail = this.feedback.mail;
                if(content.length < 1){
                    pageTips2("问题建议不能为空");
                    return;
                }
                if(!isMail(mail)){
                    pageTips2("请输入正确邮箱地址");
                    return;
                }
                var data = '{"Action":"019001",'+wsStr+'"u_loginname":"","Tag":{"c_loginname":"'+u_name+'","s_photo":"'+file+'","s_text":"'+content+'","s_email":"'+mail+'"}}';
                wsFun(base64_encode(zip(data)));
            },
            //--上传文件
            fileUpload:function (i, event) {
                //console.log(i)//--i=0身份证正面, i=1 身份证反面, i=2 问题反馈截图
                if(isImgUpload(event) === false) return;
                var that = this,
                    formFile = new FormData();
                formFile.append("action", "UploadVMKImagePath");
                formFile.append("file", event.target.files[0]);
                $.ajax({
                    type : 'post',
                    url : 'http://qq.u2n7e.cn:1026/file/upload',
                    data: formFile,
                    dataType: "json",
                    cache: false,//上传文件无需缓存
                    processData: false,//用于对data参数进行序列化处理 这里必须false
                    contentType: false, //必须
                    success : function(data){
                        if(i === 0){
                            that.Authentication.imgFace = data.filePath;
                            that.Authentication.imgFaceOk = true
                        }else if(i === 1){
                            that.Authentication.imgBack = data.filePath;
                            that.Authentication.imgBackOk = true
                        }else{
                            that.feedback.file = data.filePath;
                        }
                    }
                })
            }
        },
        watch:{
            pageShow:function (newName) {
                if(newName === 'memberInfo'){
                    var data = '{"Action":"018002",'+wsStr+'"u_id":0,"u_loginname":"","u_pswd":null,"Tag":{"c_loginname":"'+u_name+'","command":"0","c_bitname":"USDT","c_amount":"20","l_pagesize":"5","l_pageno":"1"},"SerializString":null}';
                    wsFun(base64_encode(zip(data)), false);
                }
                if(newName === 'memberInfo' || newName === 'authentication'){
                    var data = '{"Action":"018003",'+wsStr+'"u_id":0,"u_loginname":"","u_pswd":null,"Tag":{"c_loginname":"'+u_name+'","command":"0","c_bitname":"USDT","c_amount":"20","l_pagesize":"5","l_pageno":"1"},"SerializString":null}';
                    wsFun(base64_encode(zip(data)), false);
                    return
                }
                if(newName === 'updatePhone'){
                    var data = '{"Action":"015001",'+wsStr+'"Tag":{}}';
                    wsFun(base64_encode(zip(data)), false);
                }
                setTimeout(function () {
                    lzmFun()
                }, 500)
            }
        },
        computed:{}
    })
});

$(function () {

});

function getMemberInfo() {//--基本信息
    var data = '{"Action":"018001",'+wsStr+'"u_id":0,"u_loginname":"","u_pswd":null,"Tag":{"c_loginname":"'+u_name+'","command":"0","c_bitname":"USDT","c_amount":"20","l_pagesize":"5","l_pageno":"1"},"SerializString":null}';
    wsFun(base64_encode(zip(data)));
}
